<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge,chrome=1">
    <meta name="author" content="姜启航">
    <title></title>
    <style>
    *{
        box-sizing: border-box;
    }
    ul{
        margin: 0;
        padding: 0;
        list-style: none;
    }
    .box{
        width: 520px;
        height: 280px;
        margin: 0 auto;
        position: relative;
    }
    .img-list li{
        position: absolute;
        top: 0;
        left: 0;
        display: none;
    }
    .img-list li.current{
        display: block;
    }
    .indicator{
        width: 100%;
        position: absolute;
        bottom:10px;
        left: 0;
        display: flex;
        justify-content: center;
        color: white;
    }
    .indicator li{
        margin: 10px;
        width: 20px;
        height: 20px;
        background-color: #aaa;
        border-radius: 50%;
        text-align: center;
        line-height: 20px;
        cursor: pointer;
    }
    .indicator li.active{
        background-color: red;
    }
    .img-click span{
        width: 30px;
        height: 40px;
        line-height: 40px;
        text-align: center;
        color: white;
        /* border: 1px solid red; */
        background-color: rgba(0, 0, 0, 0.3);
        position: absolute;
        top: calc(50% - 20px);
        display: none;
    }
    .img-click span:hover{
        background-color: orange;
        cursor: pointer;
    }
    .img-click span.prev{
        left: 0;
    }
    .img-click span.next{
        right: 0;
    }
    </style>
</head>
<body>

    <div class="box">
        <ul class="img-list">
            <li class="current"><a href="#"><img src="img/01.jpg" alt=""></a></li>
            <li><a href="#"><img src="img/02.jpg" alt=""></a></li>
            <li><a href="#"><img src="img/03.jpg" alt=""></a></li>
            <li><a href="#"><img src="img/04.jpg" alt=""></a></li>
            <li><a href="#"><img src="img/05.jpg" alt=""></a></li>
        </ul>
        <ul class="indicator">
            <li class="active">1</li>
            <li>2</li>
            <li>3</li>
            <li>4</li>
            <li>5</li>
        </ul>
        <div class="img-click">
            <span class="prev">&lt;</span>
            <span class="next">&gt;</span>
        </div>

    </div>
    <script src="../jquery.js"></script>
</body>
</html>

<script>
         // 记录当前图片的索引值
        var index=0;
        // 上一张
        function prevImg(){
            index=index==0?$('.img-list li').length-1:index-1;
            console.log(index);
            showImg();
        }
        // 下一张
        function nextImg(){
            index=index==$('.img-list li').length-1? 0 : index+1;
            showImg();
        }
    //     // 1.自动切换图片
        var timer=setInterval(nextImg,1000);

        // 展示图片
        function showImg(){
            $('.img-list li').eq(index).addClass('current').siblings().removeClass('current')
            $('.indicator li').eq(index).addClass('active').siblings().removeClass('active');
        }
        
        $('.indicator li').each(function(){
            $(this).hover(function(){
                clearInterval(timer);
                index=$(this).index();
                showImg();
            },function(){
                timer=setInterval(nextImg,1000);
            })
        })

           // 点击按钮切换图片
    $('.box').hover(function(){
        clearInterval(timer);
        timer = null;
        $('.prev').show();
        $('.next').show();
    },function(){
        if(timer) return;
        timer = setInterval(nextImg,1000);
        $('.prev').hide();
        $('.next').hide();
    })
    $('.prev').click(function(){
        prevImg();
    });
    $('.next').click(function(){
        nextImg();
    });















</script>